package middleware

import (
	"go-mp-starter/app/common/response"
	"go-mp-starter/global"

	"github.com/gin-gonic/gin"
	"gopkg.in/natefinch/lumberjack.v2"
)

// CustomRecovery 错误日志中间件
func CustomRecovery() gin.HandlerFunc {
	logCfg := global.App.Config.Log
	return gin.RecoveryWithWriter(&lumberjack.Logger{
		Filename:   logCfg.RootDir + "/" + logCfg.Filename,
		MaxSize:    logCfg.MaxSize,
		MaxBackups: logCfg.MaxBackups,
		MaxAge:     logCfg.MaxAge,
		Compress:   logCfg.Compress,
	},
		response.ServerError)
}
